package com.zhou.simulation.consumer;

import com.alibaba.fastjson.JSON;
import com.zhou.simulation.beans.MailInfoBean;
import com.zhou.simulation.service.MailSendService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ProjectName: simulation
 * @Package: com.zhou.simulation.consumer
 * @ClassName: MailConsumer
 * @Author: zhoujingbo
 * @Description: <p>
 * @Date: 2020/10/10 15:17
 * @Version: 1.0
 */
@Component
public class MailConsumer {
    @Autowired
    MailSendService mailSendService;
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue,
                    exchange = @Exchange(
                            value = "message_send_exchange",
                            type = "topic"
                    ),
                    key = {"mail.*"}
            )
    })
    public void topicConsumer(String message) {
        System.out.println("message========" + message);
        // doSomething in here
        MailInfoBean mailInfoBean = JSON.parseObject(message,MailInfoBean.class);
        mailSendService.doMailSend(mailInfoBean);
    }
}
